package com.java.module.fire.controller.admin;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.module.fire.domain.Post;
import com.java.module.fire.service.IPostService;
import com.java.common.utils.poi.ExcelUtil;
import com.java.common.lang.domain.page.TableDataInfo;

/**
 * 帖子内容Controller
 * 
 * @author Administrator
 * @date 2025-02-10
 */
@RestController("AdminPostController")
@RequestMapping("/fire/post")
public class PostController {
    @Autowired
    private IPostService postService;

    /**
     * 查询帖子内容列表
     */
    @PreAuthorize("@ss.hasPermi('fire:post:list')")
    @GetMapping("/list")
    public TableDataInfo list(Post post) {
        WebKit.startPage();
        List<Post> list = postService.selectPostListAll(post);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出帖子内容列表
     */
    @PreAuthorize("@ss.hasPermi('fire:post:export')")
    @Log(title = "帖子内容", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Post post) {
        List<Post> list = postService.selectPostList(post);
        ExcelUtil<Post> util = new ExcelUtil<Post>(Post.class);
        return util.exportExcel(list, "post");
    }

    /**
     * 获取帖子内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('fire:post:query')")
    @GetMapping(value = "/{postId}")
    public AjaxResult getInfo(@PathVariable("postId") Long postId) {
        return AjaxResult.success(postService.selectPostById(postId));
    }

    /**
     * 新增帖子内容
     */
    @PreAuthorize("@ss.hasPermi('fire:post:add')")
    @Log(title = "帖子内容", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Post post) {
        return WebKit.toAjax(postService.insertPost(post));
    }

    /**
     * 修改帖子内容
     */
    @PreAuthorize("@ss.hasPermi('fire:post:edit')")
    @Log(title = "帖子内容", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Post post) {
        return WebKit.toAjax(postService.updatePost(post));
    }

    /**
     * 删除帖子内容
     */
    @PreAuthorize("@ss.hasPermi('fire:post:remove')")
    @Log(title = "帖子内容", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{postIds}")
    public AjaxResult remove(@PathVariable Long[] postIds) {
        return WebKit.toAjax(postService.deletePostByIds(postIds));
    }
}
